# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=opentracker
pkgver=0_git20210823
pkgrel=2
pkgdesc="an open and free bittorrent tracker"
url="http://erdgeist.org/arts/software/opentracker/"
arch="all"
license="Beerware"
makedepends="libowfat-dev zlib-dev"
install="$pkgname.pre-install"
subpackages="$pkgname-openrc ${pkgname}6"
source="https://dev.alpinelinux.org/opentracker/opentracker-$pkgver.tar.gz
	opentracker.initd
	show-version.patch
	"

builddir="$srcdir"

prepare() {
	default_prepare
	# see show-version.patch
	sed -i "s/%pkgver%/$pkgver/" opentracker/ot_stats.c
	cp -r opentracker opentracker6
}

build() {
	export FEATURES="-DWANT_IP_FROM_PROXY"
	make -C opentracker PREFIX=/usr/include

	export FEATURES="$FEATURES -DWANT_V6"
	make -C opentracker6 PREFIX=/usr/include BINARY=opentracker6
}

check() {
	opentracker/opentracker -v
	opentracker6/opentracker6 -v
}

package() {
	install -Dm755 \
		opentracker/opentracker \
		opentracker6/opentracker6 \
		-t "$pkgdir"/usr/bin

	install -Dm644 opentracker/opentracker.conf.sample \
		"$pkgdir"/etc/opentracker/opentracker.conf

	install -Dm755 "$srcdir"/opentracker.initd "$pkgdir"/etc/init.d/opentracker
	ln -s opentracker "$pkgdir"/etc/init.d/opentracker6
}

opentracker6() {
	pkgdesc="$pkgdesc (IPv6 version)"

	amove usr/bin/opentracker6
}

sha512sums="
53b9e163cf6ac349f94ef06075a7f9819e87e26501ae45a27fa0fd79d1bb0ede054739e6e9943f2e1cd51fed21e14c3da91f7a208ee2fcae87c2e659e36ece09  opentracker-0_git20210823.tar.gz
d285ca8ed873e4bc6604a8814aad738459f444fe674379c0798287eb48f116dc84a01ed1c06ad7baf3a015e0eda65fb1f08cb0f220518d9a0b7e0261b481b7d6  opentracker.initd
86b30cdb4a04d6d08c929c727e941f95134eb7707a3725a8779f2f69c3beb4eac2ec06a991236074e79798aab880223458360a4a5f4dd7e1a05ee9229e8a0c87  show-version.patch
"
